/******************************************************************************
** Name: mtime.cpp                                                           **
** Description: An object that facilitates getting the time of day from      **
**              the system RTC.  This is not the RTC object itself.          **
**                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2010  Barry Gian James.                                **
 ** All rights reserved.                                                      **
 **                                                                           **
 ** Ref: $HeadURL$
 ******************************************************************************/
// Portions (C) 2011 OpenHouseware, LLC.
// All Rights Reserved


// Last Modified $DateTime$ by $Author$

// $Id$

#include "common.h"
#include "mtime.h"


static TimeStruct  localtime(time_t t);
static void        ctime(DateStruct &, TimeStruct & ts, char * buf);

// TODO: system time is gathered from ATBIOS


MTime::MTime()
{
}

TimeStruct
MTime::Now()
{
    TimeStruct ts;
    return ts;
}

DateStruct
MTime::Date()
{
    DateStruct ds;

    // TODO: convert from BCD to decimal

    return ds;
}

void
MTime::TimeStamp(char * stamp)
{
    TimeStruct ts = Now();
    DateStruct ds = Date();
    ctime(ds,ts,stamp);
}

// TODO: complete helper functions
TimeStruct localtime(time_t t)
{
    TimeStruct ts;

    return ts;
}

void ctime(DateStruct & ds, TimeStruct & ts, char * buf)
{
    sprintf(buf,"%d/%d/%d  %d:%d:%d\r\n",ds.month,ds.day,ds.year,ts.hour,ts.min,ts.sec);
}

